#include<iostream>
#include<pthread.h>
#include<unistd.h>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond;

void* Callback(void* argc)
{
    pthread_detach(pthread_self());
    const char* name=(const char*)argc;
    while(true)
    {
        pthread_cond_wait(&cond,&mutex);
        cout<<name<<",tid::"<<pthread_self()<<",running"<<endl;
    }
    return nullptr;

}
int main()
{
    pthread_cond_init(&cond,nullptr);
    pthread_t tid1,tid2,tid3;

    pthread_create(&tid1,nullptr,Callback,(void*)"thread 1");
    pthread_create(&tid2,nullptr,Callback,(void*)"thread 2");
    pthread_create(&tid3,nullptr,Callback,(void*)"thread 3");
    
    while(true)
    {
        char c='a';
        cout<<"Please input your command:(N/Q)::";
        cin>>c;
        if(c=='N'|c=='n')
        {
            pthread_cond_broadcast(&cond);
        }
        else
            break;
        usleep(1000);
    }
        pthread_cond_destroy(&cond);
        return 0;
    }
